package com.agile.major.service.impl;

import com.agile.major.domain.ProductionAndLearningCooperation;
import com.agile.major.repository.ProductionAndLearningCooperationRepository;
import com.agile.major.service.ProductionAndLearningCooperationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Service Implementation for managing ProductionAndLearningCooperation.
 */
@Service
@Transactional
public class ProductionAndLearningCooperationServiceImpl implements ProductionAndLearningCooperationService{

    private final Logger log = LoggerFactory.getLogger(ProductionAndLearningCooperationServiceImpl.class);

    private final ProductionAndLearningCooperationRepository productionAndLearningCooperationRepository;

    public ProductionAndLearningCooperationServiceImpl(ProductionAndLearningCooperationRepository productionAndLearningCooperationRepository) {
        this.productionAndLearningCooperationRepository = productionAndLearningCooperationRepository;
    }

    /**
     * Save a productionAndLearningCooperation.
     *
     * @param productionAndLearningCooperation the entity to save
     * @return the persisted entity
     */
    @Override
    public ProductionAndLearningCooperation save(ProductionAndLearningCooperation productionAndLearningCooperation) {
        log.debug("Request to save ProductionAndLearningCooperation : {}", productionAndLearningCooperation);
        return productionAndLearningCooperationRepository.save(productionAndLearningCooperation);
    }

    /**
     *  Get all the productionAndLearningCooperations.
     *
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<ProductionAndLearningCooperation> findAll(Pageable pageable) {
        log.debug("Request to get all ProductionAndLearningCooperations");
        return productionAndLearningCooperationRepository.findAll(pageable);
    }

    /**
     *  Get one productionAndLearningCooperation by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public ProductionAndLearningCooperation findOne(Long id) {
        log.debug("Request to get ProductionAndLearningCooperation : {}", id);
        return productionAndLearningCooperationRepository.findOne(id);
    }

    /**
     *  Delete the  productionAndLearningCooperation by id.
     *
     *  @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete ProductionAndLearningCooperation : {}", id);
        productionAndLearningCooperationRepository.delete(id);
    }

    @Override
    public List<ProductionAndLearningCooperation> getProductionCooperatioByMajorAndYear(Long id, String year) {
        BaseMajor major = baseMajorRepository.findOne(id);
        if (major == null) {
            log.debug("Request to get ProductionAndLearningCooperation : {}", major);
        }
        return recruitStudentRepository.findRecruitStudentsByBaseMajorAndDataYear(major,year);
    }
}
